package com.wwp.tbshop.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.wwp.tbshop.R;
import com.wwp.tbshop.activity.cartactivity.CommitActivity;
import com.wwp.tbshop.activity.cartactivity.DeliverGoodsActivity;
import com.wwp.tbshop.activity.cartactivity.InvoiceActivity;
import com.wwp.tbshop.activity.cartactivity.PayTypeActivity;
import com.wwp.tbshop.view.custom.MyListView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by windows on 2017/6/15.
 */

public class PayActivity extends Activity {

    @Bind(R.id.ib_shopcart_back)
    ImageButton ibShopcartBack;
    @Bind(R.id.user_name)
    TextView userName;
    @Bind(R.id.user_phone)
    TextView userPhone;
    @Bind(R.id.user_address)
    TextView userAddress;
    @Bind(R.id.iv_next_detail)
    ImageView ivNextDetail;
    @Bind(R.id.edit_address)
    LinearLayout editAddress;
    @Bind(R.id.edit_pay)
    TextView editPay;
    @Bind(R.id.pay_way)
    TextView payWay;
    @Bind(R.id.iv_next_pay)
    ImageView ivNextPay;
    @Bind(R.id.delivery_time)
    TextView deliveryTime;
    @Bind(R.id.iv_next_carry)
    ImageView ivNextCarry;
    @Bind(R.id.delivery)
    LinearLayout delivery;
    @Bind(R.id.invoice_head)
    TextView invoiceHead;
    @Bind(R.id.invoice_info)
    TextView invoiceInfo;
    @Bind(R.id.invoice)
    LinearLayout invoice;
    @Bind(R.id.iv_next_bill)
    ImageView ivNextBill;
    @Bind(R.id.rv_product_list)
    MyListView mGoodsDetail;
    @Bind(R.id.count)
    TextView count;
    @Bind(R.id.goods_money)
    TextView goodsMoney;
    @Bind(R.id.delivery_money)
    TextView deliveryMoney;
    @Bind(R.id.total_money)
    TextView totalMoney;
    @Bind(R.id.btn_commit)
    Button btnCommit;
    @Bind(R.id.scrollView)
    ScrollView mScrollView;
    private Context mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account_center);
        ButterKnife.bind(this);

        mContext = this;

        testData();
        mGoodsDetail.setAdapter(new MyAdapter());

        mGoodsDetail.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    mScrollView.requestDisallowInterceptTouchEvent(false);
                } else {
                    mScrollView.requestDisallowInterceptTouchEvent(true);
                }
                return false;
            }
        });

    }

    List<String> mDatas = new ArrayList<>();

    private void testData() {
        for (int i = 0; i < 100; i++) {
            mDatas.add("我是模拟条目" + i);
        }
    }

    private class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            if (mDatas != null) {
                return mDatas.size();
            }
            return 0;
        }

        @Override
        public Object getItem(int position) {
            if (mDatas != null) {
                return mDatas.get(position);
            }
            return 0;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = View.inflate(mContext, R.layout.item_test_listview, null);
            }
            return convertView;
        }
    }

    @OnClick({R.id.iv_next_detail, R.id.iv_next_pay, R.id.iv_next_carry, R.id.iv_next_bill, R.id.btn_commit, R.id.ib_shopcart_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ib_shopcart_back:
                finish();
                break;

            case R.id.iv_next_detail:
                // TODO: 2017/6/15 整合进行跳转
                break;

            case R.id.iv_next_pay:
                Intent payTypeIntent = new Intent(this, PayTypeActivity.class);
                startActivity(payTypeIntent);
//                finish();
                break;

            case R.id.iv_next_carry:
                Intent deliverGoodsIntent = new Intent(this, DeliverGoodsActivity.class);
                startActivity(deliverGoodsIntent);
                break;

            case R.id.iv_next_bill:
                Intent billIntent = new Intent(this, InvoiceActivity.class);
                startActivity(billIntent);
                break;

            case R.id.btn_commit:
                Intent commitIntent = new Intent(this, CommitActivity.class);
                startActivity(commitIntent);
                break;
        }
    }
}
